package com.fr.schedule;

import com.fr.base.ArrayUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.util.ListMap;
import com.fr.base.xml.XMLFileReader;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.Parameter;
import com.fr.util.Utils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ViewScheduleSavedInfo
  implements Serializable, Cloneable, XMLWriter, XMLFileReader, XMLReadable
{
  private List mapList = new ArrayList();
  private List templateFileNameList = new ArrayList();
  private Parameter[] fArrayParameters = null;

  public Parameter[] getFArrayParameters()
  {
    return this.fArrayParameters;
  }

  public void setFArrayParameters(Parameter[] paramArrayOfParameter)
  {
    this.fArrayParameters = paramArrayOfParameter;
  }

  public void addMapTemplateFileName(Map paramMap, String paramString)
  {
    if ((paramMap == null) || (paramString == null))
      return;
    this.mapList.add(paramMap);
    this.templateFileNameList.add(paramString);
  }

  public boolean containTemplateFileName(String paramString)
  {
    return this.templateFileNameList.contains(paramString);
  }

  public String getTemplateFileName(Map paramMap)
  {
    return getFileName(paramMap, ".cpt");
  }

  public String getFileName(Map paramMap, String paramString)
  {
    if (paramMap.size() < 1)
      return getSingleFileName(paramString);
    String[] arrayOfString = paraName(paramMap);
    int i = this.mapList.size();
    for (int j = 0; j < i; ++j)
    {
      Map localMap = (Map)this.mapList.get(j);
      int k = 1;
      int l = 0;
      int i1 = paramMap.size();
      while (l < i1)
      {
        Object localObject = localMap.get(arrayOfString[l]);
        if ((localMap.get(arrayOfString[l]) != null) && (!(ComparatorUtils.equals(localObject, paramMap.get(arrayOfString[l])))))
        {
          k = 0;
          break;
        }
        ++l;
      }
      if ((k != 0) && (((String)this.templateFileNameList.get(j)).endsWith(paramString)))
        return ((String)this.templateFileNameList.get(j));
    }
    return "";
  }

  private String[] paraName(Map paramMap)
  {
    Set localSet = paramMap.keySet();
    String[] arrayOfString = new String[localSet.size()];
    Iterator localIterator = localSet.iterator();
    for (int i = 0; localIterator.hasNext(); ++i)
      arrayOfString[i] = ((String)localIterator.next());
    return arrayOfString;
  }

  public String getSingleFileName(String paramString)
  {
    int i = this.templateFileNameList.size();
    for (int j = 0; j < i; ++j)
      if (this.templateFileNameList.get(j).toString().endsWith(paramString))
        return this.templateFileNameList.get(j).toString();
    return "";
  }

  public String getExcelName(Map paramMap)
  {
    return getFileName(paramMap, ".xls");
  }

  public String getWordName(Map paramMap)
  {
    return getFileName(paramMap, ".doc");
  }

  public String getPDFName(Map paramMap)
  {
    return getFileName(paramMap, ".pdf");
  }

  public String[] getParameterNames()
  {
    ArrayList localArrayList = new ArrayList();
    int i = this.mapList.size();
    int j = 0;
    if (j < i)
    {
      Map localMap = (Map)this.mapList.get(j);
      Iterator localIterator = localMap.keySet().iterator();
      while (localIterator.hasNext())
        localArrayList.add("" + localIterator.next());
    }
    String[] arrayOfString = new String[localArrayList.size()];
    localArrayList.toArray(arrayOfString);
    return arrayOfString;
  }

  public Object[] getParameterValues(String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    int i = this.mapList.size();
    for (int j = 0; j < i; ++j)
    {
      Map localMap = (Map)this.mapList.get(j);
      localArrayList.add(localMap.get(paramString));
    }
    Object[] arrayOfObject = new Object[localArrayList.size()];
    localArrayList.toArray(arrayOfObject);
    return arrayOfObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ("Map".equals(str2))
      {
        ListMap localListMap = new ListMap();
        this.mapList.add(localListMap);
        paramXMLableReader.readXMLObject(new XMLReadable(this, localListMap)
        {
          private final Map val$map;
          private final ViewScheduleSavedInfo this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str1 = paramXMLableReader.getTagName();
              if ("MapKV".equals(str1))
              {
                String str2 = paramXMLableReader.getAttr("key");
                if (str2 == null)
                  return;
                paramXMLableReader.readXMLObject(new ViewScheduleSavedInfo.2(this, str2));
              }
            }
          }

          static Map access$000(1 param1)
          {
            return param1.val$map;
          }
        });
      }
      else if ("TemplateFileName".equals(str2))
      {
        String str1;
        if ((str1 = paramXMLableReader.getElementValue()) != null)
          this.templateFileNameList.add(str1);
      }
      else if ("Parameters".equals(str2))
      {
        setFArrayParameters(ReportXMLUtils.readParameters(paramXMLableReader));
      }
    }
  }

  public Object readFileContent(XMLableReader paramXMLableReader)
  {
    ViewScheduleSavedInfo localViewScheduleSavedInfo = new ViewScheduleSavedInfo();
    paramXMLableReader.readXMLObject(localViewScheduleSavedInfo);
    return localViewScheduleSavedInfo;
  }

  public Object errorHandler()
  {
    return new ViewScheduleSavedInfo();
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    Object localObject1;
    paramXMLPrintWriter.startTAG("ViewScheduleSavedInfo");
    for (int i = 0; i < this.mapList.size(); ++i)
    {
      localObject1 = (Map)this.mapList.get(i);
      paramXMLPrintWriter.startTAG("Map");
      Iterator localIterator = ((Map)localObject1).keySet().iterator();
      while (localIterator.hasNext())
      {
        Object localObject2 = localIterator.next();
        Object localObject3 = ((Map)localObject1).get(localObject2);
        paramXMLPrintWriter.startTAG("MapKV").attr("key", Utils.objectToString(localObject2));
        ReportXMLUtils.writeObject(paramXMLPrintWriter, localObject3);
        paramXMLPrintWriter.end();
      }
      paramXMLPrintWriter.end();
    }
    for (i = 0; i < this.templateFileNameList.size(); ++i)
    {
      localObject1 = (String)this.templateFileNameList.get(i);
      paramXMLPrintWriter.startTAG("TemplateFileName").textNode((String)localObject1).end();
    }
    if (!(ArrayUtils.isEmpty(this.fArrayParameters)))
      ReportXMLUtils.writeParameters(paramXMLPrintWriter, this.fArrayParameters);
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}